#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>

int main(int argc, char **argv){
    
    int fd;
    struct input_event in_ev = {0};

    if(argc < 2){
        printf("Usage: %s /dev/input/eventX\n", argv[0]);
        return -1;
    }

    fd = open(argv[1], O_RDWR);
    if(fd < 0){
        printf("open fail: %s\n", argv[1]);
    }

    for(;;){

        if(sizeof(struct input_event) != read(fd, &in_ev, sizeof(struct input_event))){
            printf("read error");
            return -1;
        }

        printf("type:%d code:%d value:%d\n",in_ev.type, in_ev.code, in_ev.value);
    }  

    close(fd);
}